package com.cjj.volatile_thread;

import java.util.concurrent.atomic.AtomicInteger;

class VolatileAtomic extends Thread{

    private static AtomicInteger atomicInteger = new AtomicInteger(0);

    @Override
    public void run() {
        for (int i = 0; i < 1000; i++){
            atomicInteger.incrementAndGet();
        }
        System.out.println(getName() + "----" + atomicInteger);
    }
}

/**
 * @ClassName Volatile_Atomic
 * Volatile不具有原子性
 * @Date 2021/07/18 20:37:57
 * @Created by ccc-j
 * @email ccc-ju@outlook.com
 */
public class Volatile_Atomic {

    public static void main(String[] args) {
        VolatileAtomic[] t = new VolatileAtomic[10];
        for(int i = 0; i < t.length; i++){
            t[i] = new VolatileAtomic();
        }
        for (int i = 0; i < t.length; i++){
            t[i].start();
        }
    }

}
